package com.demo.inboundhandlerandoutboundhandler.server;

import com.demo.inboundhandlerandoutboundhandler.codec.MyByteToLongDecoder;
import com.demo.inboundhandlerandoutboundhandler.codec.MyByteToLongDecoder2;
import com.demo.inboundhandlerandoutboundhandler.codec.MyLongToByteEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

/**
 * @author gy
 * @date 2022/7/31
 */
public class MyServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();

        // 1、 入站 的 handler 进行解码 MyByteToLongDecoder
//        pipeline.addLast(new MyByteToLongDecoder());
        pipeline.addLast(new MyByteToLongDecoder2());

        // 发送数据给客户端 需要一个 编码器 加入一个出站的编码器（同样属于handler）
        pipeline.addLast(new MyLongToByteEncoder());

        // 2、 自定义的handler 处理业务逻辑
        pipeline.addLast(new MyServerHandler());
    }
}
